#ifndef PROXY_BASE_DNS_SOLUTION_H_
#define PROXY_BASE_DNS_SOLUTION_H_
#include "proxy/base/proxybase.h"

namespace proxy{
  class DnsServer : public boost::noncopyable,
    public boost::enable_shared_from_this < DnsServer > {
  public:
    typedef boost::shared_ptr<DnsServer> Ptr;
    DnsServer(boost::asio::io_service &io_serivce);
    bool StartDnsServer();
    void StopDnsServer();
  private:
    static const unsigned short DEFAULT_DNS_PORT = 53;
    static const int DNS_RECEIVE_BUFFER_SIZE = 1024 * 16;
    typedef boost::shared_ptr<boost::asio::ip::udp::socket> UdpSocketPtr;
    typedef boost::shared_ptr<boost::asio::ip::udp::endpoint> UdpEndpointPtr;

    bool StartReceiveDnsRequestion();
    void HandleReceiveDnsRequestion(UdpEndpointPtr client_endpoint,
      const boost::system::error_code& error, std::size_t bytes_transferred);
  private:

    boost::asio::io_service &io_serivce_;
    UdpSocketPtr dns_socket_;
    bool is_running_;
    char recv_buffer_[DNS_RECEIVE_BUFFER_SIZE];
  };
}

#endif PROXY_BASE_DNS_SOLUTION_H_